<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>办公家具运维系统v1.0</title>
        <meta name="description" content="办公家具运维系统">
        <meta name="keywords" content="办公家具运维系统">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>任务管理</h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>任务管理</el-breadcrumb-item>
                    <el-breadcrumb-item>任务列表</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-button type="primary" class="butT" @click="handleCreate()">新建家具</el-button>
                        <el-button type="primary" class="butT" @click="handleTask()">发起任务</el-button>
                        <el-input placeholder="家具Id" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="_findPage()" class="dalfBut">查询家具</el-button>
                        <el-input placeholder="用户名" v-model="userName" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="_findTask()" class="dalfBut">查询申请单</el-button>
                    </div>
                    <!--table1-->
                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="applyId" label="申请单编号" align="center"></el-table-column>
                        <el-table-column prop="taskId" label="任务号" align="center"></el-table-column>
                        <el-table-column prop="step" label="阶段" align="center"></el-table-column>
                        <el-table-column prop="status" label="状态" align="center"></el-table-column>
                        <el-table-column prop="process" label="流程类别" align="center"></el-table-column>
                        <el-table-column prop="comment" label="备注" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="taskFormShow()">审批</el-button>
                                <!--<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>-->
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!--table2-->
                    <el-table size="small" current-row-key="id" :data="furnDataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="furnId" label="家具Id" align="center"></el-table-column>
                        <el-table-column prop="furnDept" label="部门" align="center"></el-table-column>
                        <el-table-column prop="furnArea" label="区域" align="center"></el-table-column>
                        <el-table-column prop="furnLoc" label="位置" align="center"></el-table-column>
                        <el-table-column prop="furnLocDtl" label="详细位置" align="center"></el-table-column>
                        <el-table-column prop="furnCategory" label="类别" align="center"></el-table-column>
                        <el-table-column prop="furnName" label="名称" align="center"></el-table-column>
                        <el-table-column prop="furnNo" label="编号" align="center"></el-table-column>
                        <el-table-column prop="furnCode" label="编码" align="center"></el-table-column>
                        <el-table-column prop="furnYear" label="使用起始年份" align="center"></el-table-column>
                        <el-table-column prop="furnStatus" label="状态" align="center"></el-table-column>
                        <el-table-column prop="version" label="详细位置" align="center"></el-table-column>
                        <!--<el-table-column label="操作" align="center">-->
                            <!--<template slot-scope="scope">-->
                                <!--<el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>-->
                                <!--&lt;!&ndash;<el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>&ndash;&gt;-->
                            <!--</template>-->
                        <!--</el-table-column>-->
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleFurnCurrentChange"
                                :current-page="furnPagination.currentPage"
                                :page-size="furnPagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="furnPagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="新增家具信息" :visible.sync="dialogFormVisible">
                            <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="家具Id" prop="furnId">
                                            <el-input v-model="formData.furnId"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="部门" prop="furnDept">
                                            <el-input v-model="formData.furnDept"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="区域" prop="furnArea">
                                            <el-input v-model="formData.furnArea"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="位置" prop="furnLoc">
                                            <el-input v-model="formData.furnLoc"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="详细位置" prop="furnLocDtl">
                                            <el-input v-model="formData.furnLocDtl"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="类别" prop="furnCategory">
                                            <el-input v-model="formData.furnCategory"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="名称" prop="furnName">
                                            <el-input v-model="formData.furnName"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="编号" prop="furnNo">
                                            <el-input v-model="formData.furnNo"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="编码" prop="furnCode">
                                            <el-input v-model="formData.furnCode"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="开始年份" prop="furnYear">
                                            <el-input v-model="formData.furnYear"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="状态" prop="furnStatus">
                                            <el-input v-model="formData.furnStatus"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="版本" prop="version">
                                            <el-input v-model="formData.version"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="handleAdd()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!-- 编辑标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="发起任务" :visible.sync="dialogFormVisible4Edit">
                            <el-form ref="dataEditForm" :model="taskData" :rules="taskRules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="部门负责人">
                                            <el-select v-model="taskData.departmentUserName">
                                                <el-option label="test1" value="test1"></el-option>
                                                <el-option label="test2" value="test2"></el-option>
                                                <el-option label="test3" value="test3"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="PO管理员">
                                            <el-select v-model="taskData.defaultPOUserName">
                                                <el-option label="test4" value="test4"></el-option>
                                                <el-option label="test5" value="test5"></el-option>
                                                <el-option label="test6" value="test6"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="PO负责人">
                                            <el-select v-model="taskData.seniorPOUserName">
                                                <el-option label="test7" value="test7"></el-option>
                                                <el-option label="test8" value="test8"></el-option>
                                                <el-option label="test9" value="test9"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="流程类别">
                                            <el-select v-model="taskData.flowCategory">
                                                <el-option label="新增" value="0"></el-option>
                                                <el-option label="报修" value="1"></el-option>
                                                <el-option label="转移" value="2"></el-option>
                                                <el-option label="报废" value="3"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="家具Id号">
                                            <el-input type="text" v-model="taskData.furnIdList"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="用户名">
                                            <el-input type="text" v-model="taskData.userName"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="handleEdit()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>

                    <!--审批标签弹层-->
                    <div class="add-form">
                        <el-dialog title="审批任务" :visible.sync="dialogFormVisible4Task">
                            <el-form ref="dataTaskForm" :model="approvalData" :rules="approvalRules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="申请单Id">
                                            <el-input type="text" v-model="approvalData.applyId"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="任务Id号">
                                            <el-input type="text" v-model="approvalData.taskId"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="审批意见">
                                            <el-select v-model="approvalData.approved">
                                                <el-option label="同意" value="Y"></el-option>
                                                <el-option label="拒绝" value="N"></el-option>
                                            </el-select>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="备注">
                                            <el-input type="text" v-model="approvalData.comment"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="当前审批用户名">
                                            <el-input type="text" v-model="approvalData.approvalName"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Task = false">取消</el-button>
                                <el-button type="primary" @click="handleApproval()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
                    queryString:null//查询条件
				},
                furnPagination: {//分页相关模型数据
                    currentPage: 1,//当前页码
                    pageSize:10,//每页显示的记录数
                    total:0,//总记录数
                    queryString:null//查询条件
                },
				dataList: [],//当前页要展示的分页列表数据
                furnDataList:[],
                formData: {},//表单数据
                taskData: {},//发起任务表单数据
                approvalData:{},//审批任务表单数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                dialogFormVisible4Task:false,
                rules: {//校验规则
                    furnId: [{ required: true, message: '家具为必填项', trigger: 'blur' }],
                    furnName: [{ required: true, message: '家具名称为必填项', trigger: 'blur' }]
                },
                taskRules:{
                    departmentApproval: [{ required: true, message: '部门负责人为必填项', trigger: 'blur' }],
                    POApproval: [{ required: true, message: 'PO管理员为必填项', trigger: 'blur' }],
                    seniorPOApproval: [{ required: true, message: 'PO负责人为必填项', trigger: 'blur' }],
                    flowCategory: [{ required: true, message: '流程类型为必填项', trigger: 'blur' }]
                },
                userName:null,
                approvalRules:{
                    applyId: [{ required: true, message: '申请单Id为必填项', trigger: 'blur' }],
                    taskId: [{ required: true, message: '任务号为必填项', trigger: 'blur' }],
                    approved: [{ required: true, message: '审批已经为必填项', trigger: 'blur' }],
                    comment: [{ required: true, message: '备注为必填项', trigger: 'blur' }]
                }
            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();//vue对象初始化之后调用分页查询方法
            },
            methods: {
                //编辑
                handleEdit() {
                    this.$refs["dataEditForm"].validate((valid)=>{
                       if(valid){
                           //表单校验通过，发送ajax请求，可以提交数据
                           console.log(this.taskData);
                           axios.post("/work/start",this.taskData).then((response)=>{
                               //关闭编辑窗口
                              if(response.data.flag){
                                  //弹出成功的信息
                                  this.$message({
                                      type:'success',
                                      message:response.data.message
                                  });
                              }else{
                                  this.$message.error(response.data.message);
                              }
                           }).finally(()=>{
                               //不管成功还是失败，都调用分页查询方法
                               this.dialogFormVisible4Edit=false;
                               });

                       }else{
                           //表单校验不通过
                           this.$message.error("表单数据校验失败！");
                           return false;
                       }
                    });
                },
                //添加
                handleAdd () {
                    //进行表单校验
                    this.$refs['dataAddForm'].validate((valid) => {
                        if(valid){
                            //表单校验通过，发生ajax请求，将录入的数据提交到后台进行处理
                            console.log(this.formData);
                            axios.post("/work/addFurn",this.formData).then((res) => {
                                //关闭新增窗口
                                this.dialogFormVisible = false;
                                if(res.data.flag){//执行成功
                                    //新增成功后，重新调用分页查询方法，查询出最新的数据
                                    this.findPage();
                                    //弹出提示信息
                                    this.$message({
                                        message:res.data.message,
                                        type:'success'
                                    });
                                }else{//执行失败
                                    //弹出提示
                                    this.$message.error(res.data.message);
                                }
                            });
                        }else{
                            //校验不通过
                            this.$message.error("数据校验失败，请检查你的输入信息是否正确！");
                            return false;
                        }
                    });
                },
                //分页查询
                findPage() {
                    //发送ajax请求，提交分页相关请求参数（页码、每页显示记录、查询条件）
                    var param={
                        currentPage: this.furnPagination.currentPage,
                        pageSize: this.furnPagination.pageSize,
                        vague: this.furnPagination.queryString
                    };
                    axios.post("/work/findFurnPage",param).then((response)=>{
                       //解析controller响应回的数据
                        this.furnPagination.total=  response.data.total;
                        this.furnDataList=response.data.rows;
                    });
                },
                _findPage(){
                    this.furnPagination.currentPage=1;
                    this.findPage();
                },
                _findTask(){
                    axios.get("/work/getTask?userName="+this.userName).then((response)=>{
                        //解析controller响应回的数据
                        this.pagination.total=  response.data.total;
                        this.dataList=response.data.rows;
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData={};//把表单数据重置
                },
                resetTaskForm(){
                    this.taskData={};
                },
                // 弹出添加窗口
                handleCreate() {
                    //点击按钮触发这次函数，能弹出新增按钮
                    this.dialogFormVisible =true;
                    this.resetForm();
                },

                // 弹出编辑窗口
                handleTask() {
                    //点击按钮触发这次函数，能弹出新增按钮
                    this.dialogFormVisible4Edit =true;
                    this.resetTaskForm();
                },
                //切换页码
                handleCurrentChange(currentPage) {
                    //重新调用findpage方法进行分页查询，页码发生变化
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                handleFurnCurrentChange(currentPage) {
                    //重新调用findpage方法进行分页查询，页码发生变化
                    this.pagination.currentPage=currentPage;
                    this.findPage();
                },
                taskFormShow() {
                    //弹出编辑窗口
                    this.dialogFormVisible4Task = true;
                    //回显数据,发送ajax请求根据id查询当前检查项
                    this.approvalData={};
                },
                handleApproval(){
                    //进行表单校验
                    this.$refs['dataTaskForm'].validate((valid) => {
                        if(valid){
                            //表单校验通过，发生ajax请求，将录入的数据提交到后台进行处理
                            console.log(this.approvalData);
                            axios.post("/work/complete",this.approvalData).then((res) => {
                                //关闭新增窗口
                                this.dialogFormVisible4Task = false;
                                if(res.data.flag){//执行成功
                                    //新增成功后，重新调用分页查询方法，查询出最新的数据
                                    //弹出提示信息
                                    this.$message({
                                        message:res.data.message,
                                        type:'success'
                                    });
                                }else{//执行失败
                                    //弹出提示
                                    this.$message.error(res.data.message);
                                }
                            });
                        }else{
                            //校验不通过
                            this.$message.error("数据校验失败，请检查你的输入信息是否正确！");
                            return false;
                        }
                    });
                },
                // 删除
                handleDelete(row) {//row其实是一个json对象，它的结构是｛｝
                    this.$confirm("您确定要删除此条数据吗？","提示",{
                        type:'warning'
                    }).then(()=>{
                        axios.get("/person/delete.do?id="+row.id).then((response)=>{
                            if(response.data.flag){
                                //执行成功
                                //弹出成功的提示信息
                                this.$message({
                                    type:'success',
                                    message:response.data.message
                                });
                                this.findPage();
                            }else{
                                //执行失败
                                this.$message.error(response.data.message);
                            }
                        });
                    }).catch(()=>{
                        this.$message({
                            type:'info',
                            message:'操作已取消'
                        });
                    });
                }
            }
        })
    </script>
</html>